package leecode.stringAndArray.summary;

/**
 * 给定一个字符串 s ，你需要反转字符串中每个单词的字符顺序，同时仍保留空格和单词的初始顺序。
 */
public class ReverseWords {
    public static void main(String[] args) {
        System.out.println(reverseWords("Let's take LeetCode contest"));
    }

    public static String reverseWords(String s) {
        String[] strs = s.split(" ");
        for (int i = 0; i < strs.length; i++) {
            strs[i] = new StringBuffer(strs[i]).reverse().toString();
        }

        StringBuffer stringBuffer = new StringBuffer();
        String ans;
        for (int i = 0; i < strs.length; i++) {
           stringBuffer.append(strs[i]+" ");
        }
        return stringBuffer.toString().trim();
    }
}
